var _ajax = require('../../utils/ajax'); // 请求函数
Page({
    /**
     * 页面的初始数据
     */
    data: {
        items: [{
                name: '男',
                value: '1',
                color: '#D32524',
                checked: 'true'
            },
            {
                name: '女',
                value: '2',
                color: '#D32524'
            },
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        _ajax.getUserInfo(function (data) {
            if (data.code == 0) {
                that.setData({
                    admin_name: data.data.admin_name
                });
            }
        }, this);
        that.setData({
            courseId: options.courseId
        });
        _ajax.getConfig(function (data) {
            if (data.code == 0) {
                that.setData({
                    phone: data.data.phone
                });
            }
        }, this);
    },
    formSubmit(e) {
        var that = this;
        var obj = e.detail.value;
        var sayObj = {
            contact: '请输入参会人姓名',
            phone: '请输入联系电话',
            company: '请输入所在公司',
            position: '请输入当前职务',
            address: '请输入公司地址',
            admin_name: '请输入邀请人姓名'
        }
        obj.course_id = that.data.courseId;
        for (var key in obj) {
            if (!obj[key]) {
                wx.showToast({
                    title: sayObj[key],
                    icon: 'none'
                });
                return;
            }
        }
        _ajax.getBugCourseInfo(obj, function(data) {
            if (data.code == 0) { // 课程下架
                wx.navigateTo({
                    url: '../wxPay/wxPay?orderId=' + data.data.order_id,
                });
            } else {
                setTimeout(function(){
                    wx.showToast({
                        title: data.msg,
                        icon: 'none',
                        duration: 1000
                    });
                    if (data.code == 3) {
                        setTimeout(function () {
                            wx.switchTab({
                                url: '../index/index'
                            });
                        }, 1000);
                    }
                }, 500);
            }
        }, this);
    },
    fnCallPhone: function(){
        var that = this;
        wx.makePhoneCall({
            phoneNumber: that.data.phone,
        });
    }
})